package olga.gorbatiuk.perdep.sorting.arrayfiller;

import java.util.Random;

/**
 * @author Olga Gorbatiuk
 */
public abstract class AbstractArrayFiller {

    protected int[] getRandomlyFilledArray(int min, int max, int size) {
        if (min > max) {
            throw new IllegalArgumentException(
                    "Min value should be less or equals Max value");
        }
        if (size < 1) {
            throw new IllegalArgumentException("Array must not be empty");
        }

        int[] array = new int[size];
        fillArrayRandomly(min, max, size, array);
        return array;
    }

    protected void fillArrayRandomly(int min, int max, int size, int[] array) {
        Random random = new Random();

        for (int i = 0; i < size; i++) {
            array[i] = random.nextInt(max + 1 - min) + min;
        }
    }

}
